package cn.jiyun.controller;

import cn.jiyun.pojo.Day3;
import cn.jiyun.service.UService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("user")
public class UController {
    @Autowired
    private UService uService;

    @GetMapping("findAll")
    public String findAll(Model model, Page page, String name, String age, String zt) {
        Page<Day3> page1 = new Page<>();
        page1.setCurrent(page.getCurrent());
        page1.setSize(2);
        QueryWrapper<Day3> queryWrapper = new QueryWrapper<>();
        if (zt == null) {
            queryWrapper.eq("zt", 0);
        } else {
            queryWrapper.eq("zt", zt);
        }
        queryWrapper.like(name != null, "name", name);
        queryWrapper.gt(age != null, "age", age);
        Page<Day3> list = uService.findAll(page1, queryWrapper);
        model.addAttribute("list", list);
        return "ulist";
    }


    @GetMapping("del")
    public String del(Integer id) {
        uService.del(id);
        return "redirect:findAll";
    }


}
